﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using RuleCode.Table;
namespace map.member.money
{
    public partial class shouru : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitPage();
                bind1();
            }
        }

        #region 辅助方法
        private void bind1()
        {
            if (AliApi.appUserId != string.Empty)
            {
                string filter = string.Empty;
                if (StartDateTextBox.Text != string.Empty)
                    filter += " and jccreatedate>= '"+StartDateTextBox.Text+"'" ;
                if (EndDateTextBox.Text != string.Empty)
                    filter += " and jccreatedate <= '" + EndDateTextBox.Text+" 23:59:59'";
                if (this.TransTypeDropDownList.SelectedValue != "")
                    filter += " and cbmoneytrantype='"+this.TransTypeDropDownList .SelectedValue +"'";
                cbmoneytrans moneytrans = cbmoneytrans.Find("cbuserid='" + AliApi.appUserId + "'" + filter);
                WebPager1.DataSource = moneytrans.MyTable;     
                WebPager1.DataBind(); 
            }
        }
        
        private void InitPage()
        {
            DateTime now = DateTime.Now;
            this.StartDateTextBox.Text = now.Year.ToString() + "-" + now.Month.ToString() + "-1";
            this.EndDateTextBox.Text = now.ToShortDateString();

            this.TransTypeDropDownList.Items.Clear();
            this.TransTypeDropDownList.Items.Add(new ListItem("全部", ""));
            this.TransTypeDropDownList.Items.Add(new ListItem(MONEY_TransType.Block, MONEY_TransType.Block));
            this.TransTypeDropDownList.Items.Add(new ListItem(MONEY_TransType.BuyOut, MONEY_TransType.BuyOut));
            this.TransTypeDropDownList.Items.Add(new ListItem(MONEY_TransType.Refund, MONEY_TransType.Refund));
            this.TransTypeDropDownList.Items.Add(new ListItem(MONEY_TransType.SaleIn, MONEY_TransType.SaleIn));
            this.TransTypeDropDownList.Items.Add(new ListItem(MONEY_TransType.UnBlock, MONEY_TransType.UnBlock));
            this.TransTypeDropDownList.Items.Add(new ListItem(MONEY_TransType.ChargeIn, MONEY_TransType.ChargeIn));
            this.TransTypeDropDownList.Items.Add(new ListItem(MONEY_TransType.WithDraw, MONEY_TransType.WithDraw));
            this.TransTypeDropDownList.SelectedIndex = 0;
        }

        protected string GetSubString(string src, int count)
        {
            if (count > 0)
                return (src.Length > count + 3) ? src.Substring(0, count) + "..." : src;
            else
                return src;
        }
        #endregion

        #region 事件
        protected void Button1_Click(object sender, EventArgs e)
        {
            bind1();
        }

        protected void WebPager1_PageIndexChanged(object sender, RuleCode.Controls.PageChangedEventArgs e)
        {
            WebPager1.CurrentPageIndex = e.NewPageIndex;
            bind1();
        }
        #endregion
    }
}
